package com.xykj.enterprise.wechat.ext.api.externalcontact;

import com.xykj.enterprise.wechat.bean.ext.externalcontact.ExternalContactListVo;
import com.xykj.enterprise.wechat.ext.service.customer.ExternalContactService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Function(description = "获取客户列表", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "userid", type = Type.String, description = "企业成员的userid", required = true),
})
@Component
public class ExternalContactList implements Action {

    @Autowired
    private ExternalContactService externalContactService;

    @Override
    public Response execute(Request request) throws Exception {
        String userid = request.getString("userid");
        ExternalContactListVo rsp = externalContactService.externalContactList(
                request.getString("access_token"),
                userid
        );

        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success().put("data", rsp);
    }
}
